<template>
	<div class="app-container">
		<jk-operation-card ref="box1" class="margin-bottom-10">
			<div class="flex-between-center-wrap">
				<div class="flex-start-center-wrap"></div>
				<div class="flex-end-center-wrap">
					<el-date-picker
						v-model="searchParams.yearMonth"
						clearable
						type="month"
						size="small"
						style="width: 120px"
						class="search-bar-item-size4 item-gap"
					></el-date-picker>
					<jk-select
						v-model="searchParams.processId"
						:option-list="processList"
						clearable
						size="small"
						placeholder="工序"
						class="search-bar-item-size1 item-gap"
					></jk-select>
					<jk-select
						v-model="searchParams.workshopId"
						:clearable="true"
						:option-list="workshopList"
						placeholder="区域"
						class="search-bar-item-size1 margin-5-0 item-gap"
					></jk-select>
					<jk-search-button @click="onSearchBtn"></jk-search-button>
				</div>
			</div>
		</jk-operation-card>

		<jk-card>
			<jk-table
				ref="jkTable"
				:loading="tableLoading"
				:data="tableData"
				:height="tableHeight + 10"
			>
				<vxe-column
					v-for="(item, index) in tableColumnList"
					:key="index"
					:title="item.title"
					:align="item.align"
					:field="item.keyName"
					:sortable="item.sortable"
					:fixed="item.fixed ? item.fixed : ''"
					:min-width="item.minWidth"
					:width="item.width"
				>
					<template slot-scope="scope">
						<jk-state-bar
							v-if="item.keyName === 'auditState'"
							:state="scope.row.auditState"
							:state-list="stateList"
						></jk-state-bar>
						<span v-else>{{ scope.row[item.keyName] }}</span>
					</template>
				</vxe-column>
			</jk-table>

			<!-- 分页组件 -->
			<footer ref="box2" class="flex-end-center margin-top-10">
				<jk-page
					:page-index="searchParams.pageNo"
					:page-sizes="searchParams.pageSizes"
					:page-size="searchParams.pageSize"
					:total="totalCount"
					@on-change="onPageChange"
				/>
			</footer>
		</jk-card>
	</div>
</template>

<script>
    import calHeight from '/src/mixins/cal-table-height';
    import { formatMonth, pageConfig, tipsBar } from '/src/utils/jk/jk-tool';
    import getMenuColumn from '../../../../mixins/getMenuColumn';
    import handlerCache from '../../../../mixins/handler-cache';
    import permissionMixin from '../../../../mixins/permission-mixin';
    import { machineManagerUpkeepDispatchCreate } from '../../../../api/machine/upkeepMonthRecord';
    export default {
        name: 'UpkeepMonthRecord',
        components: {
        },
        mixins: [calHeight, getMenuColumn, handlerCache, permissionMixin],
        data() {
            return {
                apiItem: {
                    'page': machineManagerUpkeepDispatchCreate
                },
                stateList: [
                    { id: 0, name: '未完成', color: '#ff9900' },
                    { id: 1, name: '已完成', color: '#0bab5b' },
                    { id: -1, name: '全部', color: '#2d8cf0' }
                ],
                tableLoading: true,
                tableData: [],
                processList: [],
                workshopList: [],
                totalCount: 0,
                searchParams: {
                    pageNo: 1,
                    pageSize: pageConfig.pageSize,
                    yearMonth: '',
                    processId: null
                }
            };
        },
        methods: {
            onStateChange() {
                this.$set(this.searchParams, 'pageNo', 1);
                this.getListRequest();
            },
            onPageChange(pageIndex, pageSize) {
                this.searchParams.pageNo = pageIndex;
                this.searchParams.pageSize = pageSize;
                this.getListRequest();
            },
            /** 查询列表 */
            getListRequest() {
                this.tableLoading = true;
                const params = JSON.parse(JSON.stringify(this.searchParams));
                if (params.auditState === -1) params.auditState = null;
                this.apiItem.page(params).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res || [];
                        this.totalCount = res.data.count;
                    }
                });
            },
            /** 搜索按钮操作 */
            onSearchBtn() {
                this.searchParams.pageNo = 1;
                this.totalCount = 1;
                this.getListRequest();
            },
            clearCacheMethod() {
                // Object.assign(this.$data, this.$options.data());
                this.$nextTick(() => {
                    this.getDependentData();
                });
            },
            async getDependentData() {
                this.processList = this.$store.state.user.userProcess.processList;
                this.workshopList = this.$store.state.user.userWorkshop.workshopList;
                this.$set(this.searchParams, 'yearMonth', formatMonth(Date.now()));
                await this.getMenuColumnListRequest();
                await this.getListRequest();
            }
        },
        mounted() {
            this.getDependentData();
        }
    };
</script>
